package com.retail.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.retail.order.domain.Take;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.order.domain.TTake;
import com.retail.order.service.ITTakeService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 收货Controller
 * 
 * @author retail
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/take")
public class TTakeController extends BaseController
{
    @Autowired
    private ITTakeService tTakeService;

    /**
     * 查询收货列表
     */
    @RequiresPermissions("order:take:list")
    @GetMapping("/list")
    public TableDataInfo list(TTake tTake)
    {
        startPage();
        List<TTake> list = tTakeService.selectTTakeList(tTake);
        return getDataTable(list);
    }

    /**
     * 导出收货列表
     */
    @RequiresPermissions("order:take:export")
    @Log(title = "收货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTake tTake)
    {
        List<TTake> list = tTakeService.selectTTakeList(tTake);
        ExcelUtil<TTake> util = new ExcelUtil<TTake>(TTake.class);
        util.exportExcel(response, list, "收货数据");
    }

    /**
     * 获取收货详细信息
     */
    @RequiresPermissions("order:take:query")
    @GetMapping(value = "/{takeId}")
    public Result getInfo(@PathVariable("takeId") Long takeId)
    {
        return success(tTakeService.selectTTakeByTakeId(takeId));
    }

    /**
     * 新增收货
     */
    @RequiresPermissions("order:take:add")
    @Log(title = "收货", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TTake tTake)
    {
        return toAjax(tTakeService.insertTTake(tTake));
    }

    /**
     * 修改收货
     */
    @RequiresPermissions("order:take:edit")
    @Log(title = "收货", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TTake tTake)
    {
        return toAjax(tTakeService.updateTTake(tTake));
    }

    /**
     * 删除收货
     */
    @RequiresPermissions("order:take:remove")
    @Log(title = "收货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{takeIds}")
    public Result remove(@PathVariable Long[] takeIds)
    {
        return toAjax(tTakeService.deleteTTakeByTakeIds(takeIds));
    }

    @GetMapping("getAddress")
    public Result<List<TTake>> getAddress(Long userId){
        List<TTake> take=tTakeService.getAddress(userId);
        return Result.success(take);
    }
}
